<template>
  <div class="wrapper">
    <el-card>
      <div class="rowDiv">
        <div class="row-left">
          <div class="row-item">时间范围:<Date @dateFun="dateFun"></Date></div>
          <div class="row-item">
            调出仓库:<el-select
              v-model="state.trans_out_id"
              placeholder="选择调出仓库"
            >
              <template v-for="child in state.wareData" :key="child.id">
                <el-option
                  :value="child.warehouse_id"
                  :label="child.name"
                ></el-option>
              </template>
            </el-select>
          </div>
          <div class="row-item">
            调入仓库:<el-select
              v-model="state.trans_in_id"
              placeholder="选择调入仓库"
            >
              <template v-for="child in state.wareData" :key="child.id">
                <el-option
                  :value="child.warehouse_id"
                  :label="child.name"
                ></el-option>
              </template>
            </el-select>
          </div>
        </div>
        <div class="row-right">
          <el-button type="primary" @click="new_trans">新建调拨</el-button>
        </div>
      </div>
      <el-table
        ref="multipleTable"
        :data="state.tableData"
        style="width: 100%; margin-top: 20px"
      >
        <el-table-column prop="serial_no" label="调拨单号"> </el-table-column>
        <el-table-column label="商品名称" width="200px;">
          <template v-slot="scope">
            <div v-for="item in scope.row.allocation_detail">
              {{ item.good_name }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="批次号"> </el-table-column>
        <el-table-column label="调出/调入仓库">
          <template v-slot="scope">
            <div>{{ scope.row.out_warehouse }}</div>
            <div>{{ scope.row.in_warehouse }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="调出数量（袋）">
          <template v-slot="scope">
            <div v-for="item in scope.row.allocation_detail">
              {{ item.out_count }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="out_cartons" label="调出数量（箱）">
          <template v-slot="scope">
            <div v-for="item in scope.row.allocation_detail">
              {{ item.out_cartons }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="in_count" label="调入数量（袋）">
          <template v-slot="scope">
            <div v-for="item in scope.row.allocation_detail">
              {{ item.in_count }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="out_cartons" label="调入数量（箱）">
          <template v-slot="scope">
            <div v-for="item in scope.row.allocation_detail">
              {{ item.in_cartons }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间"> </el-table-column>
        <el-table-column prop="" label="调出/入时间"> </el-table-column>
        <el-table-column prop="note" label="备注"> </el-table-column>
        <el-table-column prop="status" label="状态"> </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button
              @click.native.prevent="optionBtn(scope.row)"
              type="text"
              size="small"
            >
              操作
            </el-button>
            <el-button
              @click.native.prevent="detailRow(scope.row)"
              type="text"
              size="small"
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row type="flex">
        <el-col :span="12">
          <el-checkbox
            @change="checkAll"
            v-model="state.pageChecked"
            label="本页全选"
            name="type"
          ></el-checkbox
          ><el-button @click="unbind_all_Btn">导出</el-button>
        </el-col>
        <el-col :span="12">
          <Page
            v-if="state.totalPage"
            :totalPage="state.totalPage"
            @changePage="changePage"
          ></Page>
        </el-col>
      </el-row>
      <!-- 调拨入库弹窗 -->
      <el-dialog title="调拨入库" v-model="state.trans_in_dialog">
        <el-table :data="state.trans_show_data">
          <el-table-column prop="good_name" label="商品名称"></el-table-column>
          <el-table-column
            prop="good_out_price"
            label="出单价"
          ></el-table-column>
          <el-table-column
            prop="good_out_count"
            label="出数量"
          ></el-table-column>
          <el-table-column
            prop="good_in_price"
            label="入单价"
          ></el-table-column>
          <el-table-column label="入数量">
            <template v-slot="scope">
              <el-input v-model="scope.row.good_in_count"></el-input>
            </template>
          </el-table-column>
        </el-table>
        <el-row style="margin: 10px 0">
          备注：<el-col :span="12"
            ><el-input v-model="state.trans_note" type="textarea"></el-input
          ></el-col>
        </el-row>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="其他费用">
            <el-input
              v-model="state.other_fee"
              placeholder="其他费用"
            ></el-input>
          </el-form-item>
          <el-form-item label="调拨运费">
            <el-input
              v-model="state.db_trans_fee"
              placeholder="调拨运费"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <div>调出总额：{{ state.good_total_out }}</div>
            <div>调入总额：{{ double }}</div>
          </el-form-item>
        </el-form>
        <el-row type="flex" justify="center">
          <el-button type="text" @click="calcFun">计算入库单价</el-button>
        </el-row>
        <el-row type="flex" justify="center" style="margin-top: 20px">
          <el-col :span="3">
            <el-button @click="state.trans_in_dialog = false">取消</el-button>
          </el-col>
          <el-col :span="3">
            <el-button type="primary" @click="confirm_stock">入库</el-button>
          </el-col>
        </el-row>
      </el-dialog>
      <!-- 调拨详情 -->
      <el-drawer
        title="调拨详情"
        v-model="state.detail_dialog"
        direction="rtl"
        size="40%"
      >
        <div class="conTxt">
          <el-row>
            <el-col :span="12"
              ><h4>调拨单号:{{ state.detail_obj.serial_no }}</h4></el-col
            >
            <el-col :span="12"
              ><h4>创建时间:{{ state.detail_obj.create_time }}</h4></el-col
            >
          </el-row>
          <el-row>
            <el-col>
              <el-tag v-if="state.detail_obj.status == '已发货'" type="success"
                >已发货</el-tag
              >
              <el-tag v-if="state.detail_obj.status == '已完成'" type="info"
                >已完成</el-tag
              >
              <el-tag v-if="state.detail_obj.status == '已拒绝'" type="warning"
                >已拒绝</el-tag
              >
              <el-tag v-if="state.detail_obj.status == '待配货'" type="danger"
                >待配货</el-tag
              >
            </el-col>
          </el-row>
          <!-- step图 -->
          <el-steps :active="state.step_num" align-center>
            <el-step title="创建调拨">
              <template v-slot:description>
                <div>{{ state.detail_obj.create_name }}</div>
                <div>{{ state.detail_obj.create_time }}</div>
              </template>
            </el-step>
            <el-step title="完成审核">
              <template v-slot:description>
                <div>{{ state.detail_obj.operate_name }}</div>
                <div>{{ state.detail_obj.operate_time }}</div>
              </template>
              ></el-step
            >
            <el-step title="配送产品">
              <template v-slot:description>
                <div>{{ state.detail_obj.operate_name }}</div>
                <div>{{ state.detail_obj.operate_time }}</div>
              </template>
              ></el-step
            >
            <el-step title="调配完成" description=""></el-step>
          </el-steps>

          <div class="navTitle">1、商品信息</div>
          <el-table :data="state.detail_table">
            <el-table-column
              property="good_name"
              label="商品名称"
            ></el-table-column>
            <el-table-column label="批次号"></el-table-column>
            <el-table-column property="" label="调出/调入仓库">
              <template v-slot="scope"
                >{{ scope.row.out_warehouse }}/{{
                  scope.row.in_warehouse
                }}</template
              >
            </el-table-column>
            <el-table-column
              property="out_price"
              label="调出单价"
            ></el-table-column>
            <el-table-column property="" label="调出数量(袋)"></el-table-column>
            <el-table-column
              property="out_count"
              label="调出数量(箱)"
            ></el-table-column>
            <el-table-column
              property="in_price"
              label="调入单价"
            ></el-table-column>
            <el-table-column
              property="in_count"
              label="调入数量(袋)"
            ></el-table-column>
          </el-table>
          <div class="navTitle">2、费用信息</div>
          <table class="table table-borderd">
            <thead>
              <tr>
                <th>配送方式</th>
                <th>运输单号</th>
                <th>运费</th>
                <th>其他费用</th>
                <th>商品总金额</th>
                <th>订单总金额</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>{{ state.detail_obj.carrier }}</td>
                <td>{{ state.detail_obj.carrier_no }}</td>
                <td>{{ state.detail_obj.transport_fee }}</td>
                <td>{{ state.detail_obj.other_fee }}</td>
                <td>{{ state.detail_obj.good_total_price }}</td>
                <td>{{ state.detail_obj.total_price }}</td>
              </tr>
            </tbody>
          </table>
          <div class="navTitle">3、备注</div>
          <el-input type="textarea" :value="state.detail_obj.note" disabled>
          </el-input>
        </div>
        <el-row type="flex" justify="cenetr">
          <el-col :span="8"></el-col>
          <el-col :span="8" style="text-align: center; margin: 20px 0"
            ><el-button type="primary" @click="state.detail_dialog = false"
              >关闭</el-button
            ></el-col
          >
          <el-col :span="8"></el-col>
        </el-row>
      </el-drawer>
      <!-- 创建调拨 -->
      <el-drawer
        title="创建调拨"
        v-model="state.set_dialogVisible"
        direction="rtl"
        size="50%"
      >
        <div class="conTxt">
          <div class="navTitle">1、选择仓库</div>
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="调出仓库">
              <el-select
                placeholder="调出仓库"
                @change="out_ware_change"
                v-model="state.create_form.out_ware_id"
              >
                <template
                  v-for="item in state.wareData"
                  :key="item.warehouse_id"
                >
                  <el-option
                    :label="item.name"
                    :value="item.warehouse_id"
                  ></el-option>
                </template>
              </el-select>
            </el-form-item>
            <el-form-item label="调入仓库">
              <el-select
                placeholder="调入仓库"
                v-model="state.create_form.in_ware_id"
              >
                <template
                  v-for="item in state.wareData"
                  :key="item.warehouse_id"
                >
                  <el-option
                    :label="item.name"
                    :value="item.warehouse_id"
                  ></el-option>
                </template>
              </el-select>
            </el-form-item>
          </el-form>
          <div class="navTitle">2、调拨清单</div>
          <el-table :data="state.create_form.already_table" border style="width: 100%">
            <el-table-column label="商品名称">
              <template v-slot="scope">
                <el-select
                  @change="change_pro_sel(scope.row, $event)"
                  v-model="scope.row.selected"
                >
                  <el-option
                    v-for="item in scope.row.selectArr"
                    :key="item.good_id"
                    :label="item.good_name"
                    :value="item.good_id"
                  ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="" label="批次号"> </el-table-column>
            <el-table-column prop="good_stock" label="库存">
            <template v-slot="scope">
              {{scope.row.good_stock}}({{scope.row.good_unit}})
            </template>
            </el-table-column>
            <el-table-column prop="good_pur_price" label="进价"> </el-table-column>
            <el-table-column label="出库数量(箱)">
              <template v-slot="scope">
                <el-input
                  type="numer"
                  v-model="scope.row.send_good_num"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template #default="scope">
                <el-button type="text" @click="del(scope.$index)" size="small"
                  >移除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <el-row type="flex" justify="space-between">
            <el-col :span="12"></el-col>
            <el-col :span="12" style="text-align: right"
              ><el-button type="text" @click="addPro"
                >添加商品</el-button
              ></el-col
            >
          </el-row>
          <div class="navTitle">3、发货信息</div>
          <el-form label-width="70px" :inline="true" class="demo-form-inline">
            <el-form-item label="配送方式">
              <el-select placeholder="配送方式" v-model="state.create_form.deliver_way">
                <template v-for="item in state.create_form.deliver_way_arr" :key="item.express_code">
                  <el-option :label="item.express_name" :value="item.express_code"></el-option>
                </template>
              </el-select>
            </el-form-item>
            <el-form-item label="预计运费">
              <el-input placeholder="预计运费" type="number"
                        v-model="state.create_form.exdept_fee">
              </el-input>
            </el-form-item>
            <el-form-item label="其他费用">
              <el-input placeholder="其他费用" type="number"
                        v-model="state.create_form.other_fee"></el-input>
            </el-form-item>
            <div class="navTitle">4、备注</div>
            <el-input type="textarea" v-model="state.create_form.note"> </el-input>
            <el-row style="text-align: center">
              <el-col :span="12">商品总金额：{{create_calc.total_price.toFixed(2)}}</el-col>
              <el-col :span="12">订单总金额：{{create_calc.storage_total.toFixed(2)}}</el-col>
            </el-row>
          </el-form>
          <el-row type="flex" justify="center" style="margin-top: 20px">
            <el-col :span="4"><el-button @click="state.set_dialogVisible=false">取消</el-button></el-col>
            <el-col :span="4"
              ><el-button type="primary" @click="onSubmit"
                >创 建</el-button
              ></el-col
            >
          </el-row>
        </div>
      </el-drawer>
    </el-card>
  </div>
</template>

<script>
import { ref, reactive, computed, onMounted, getCurrentInstance } from "vue";
import { useRouter } from "vue-router";
import searchDiv from "@/components/Search.vue";
import Page from "@/components/Pagination.vue";
import Date from "@/components/Datepicker.vue";
import { ElMessageBox, ElNotification } from "element-plus";
export default {
    name:"stock_transfer",
  components: { searchDiv, Page, Date },
  props: {},
  setup() {
    //  调入库的计算
    const double = computed({
      get: () => {
        let total = 0;
        let all_pro_price = 0;
        let data = state.trans_show_data;
        data.forEach((v) => {
          all_pro_price +=
            parseFloat(v.good_out_price) * parseFloat(v.good_in_count);
        });
        total =
          Number(all_pro_price) +
          Number(state.other_fee) +
          Number(state.db_trans_fee);
        return total.toFixed(2);
      },
      set: (val) => {
        double.value = val;
      },
    });

    //  创建调拨的合计
      const create_calc = computed(() => {
          let total_price = 0;
          let storage_total = 0;
          let data = state.create_form.already_table;
          console.log(data)
          // 数量*箱规*价格
          data.forEach((v) => {
              total_price +=
                  Number(parseFloat(v.send_good_num)) *
                  Number(parseFloat(v.good_carton)) *
                  Number(parseFloat(v.good_pur_price));
          });
          storage_total +=
              total_price + Number(state.create_form.exdept_fee) + Number(state.create_form.other_fee);
      console.log(storage_total,total_price)
          let obj={
              total_price:total_price,
              storage_total:storage_total
          }
          return obj
      });
    let multipleTable = ref("null");
    const { ctx } = getCurrentInstance();
    let state = reactive({
      create_form: {
        out_ware_id: "",
        in_ware_id: '',
        temp_data: [],
        already_table: [],
          select_data_arr:[],
          exdept_fee:0,
          other_fee:0,
          note:'',
          deliver_way:'',
          deliver_way_arr:[]
      },
      set_dialogVisible: false,
      current_pro_id: "",
      trans_out_id: "",
      trans_in_id: "",
      wareData: [], //仓库
      logData: [], //物流
      trans_in_dialog: false,
      trans_show_data: [],
      trans_note: "",
      other_fee: "",
      db_trans_fee: "",
      good_total_out: "",
      good_total_in: "",
      title: "",
      begin_date: "",
      end_date: "",
      status: "",
      common_id: "",
      option_type: "",
      drawer: false,
      keyword: "",
      page: 1,
      totalPage: "",
      placeholder: "请输入您要搜索的内容",
      searchval: "",
      form: {
        ware_name: "",
        pro_name: "",
        batch_num: "",
        Inventory_num: "",
        loss_num: "",
        loss_price: "",
        loss_reason: "",
      },
      tableData: [],
      detail_dialog: false,
      step_num: "",
      detail_obj: {
        serial_no: "",
        create_time: "",
        status: "",
        detail_table: [],
      },
    });
    onMounted(() => {
      get_ware_list();
      getOrderlist();
      get_log_list();
      get_carrier_ajax();
    });
    // 创建调拨
    function new_trans() {
      state.set_dialogVisible = true;
      state.create_form.out_ware_id="";
      state.create_form.temp_data=[];
      state.create_form.already_table=[];
      state.create_form.exdept_fee=0;
      state.create_form.other_fee=0;
      state.create_form.note='';
      state.create_form.deliver_way='';
    }
    // 日期
    function dateFun(e) {
      state.begin_date = e.begin_date;
      state.end_date = e.end_date;
      getOrderlist();
    }
    // 计算入库单价
    function calcFun() {
      console.log(state.trans_show_data);
      let data = state.trans_show_data;
      let allocation_list = [];
      data.forEach((v) => {
        let obj = {
          in_count: v.good_in_count,
          id: v.id,
        };
        allocation_list.push(obj);
      });
      let json_obj = {
        allocation_list: allocation_list,
        other_fee: state.other_fee,
        transport_fee: state.db_trans_fee,
      };
      ctx.$http
        .post("/tanxiaji/allocate_calculate_in_price/", {
          data: JSON.stringify(json_obj),
        })
        .then((res) => {
          if (res.errno == 0) {
            console.log(double);
            double._value = res.data.total_in_price;
            ElNotification.success(res.errmsg);
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    // 调出仓库改变
    function out_ware_change(e) {
      state.create_form.already_table = [];
      console.log(e);
      get_ware_pro(e);
    }
    //  获取当前仓库的数据
    function get_ware_pro(id) {
      ctx.$http
        .post("/tanxiaji/allocate_search_goods/", {
          src_warehouse_id:id,
          des_warehouse_id: state.create_form.in_ware_id,
        })
        .then((res) => {
          if (res.errno == 0) {
            let list = res.data.good_list;
            state.create_form.temp_data=JSON.parse(JSON.stringify(list));
            if(!list.length)return;
            let select_Arr = [];
            list.filter((v) => {
              v['send_good_num']=0;
              let obj={
                good_id:v.good_id,
                good_name:v.good_name
              }
                select_Arr.push(obj);
            });
              state.create_form.select_data_arr=select_Arr;
            let obj={
              good_id:list[0].good_id,
              good_name:list[0].good_name,
              good_pur_price:list[0].good_pur_price,
              good_spec:list[0].good_spec,
              good_stock:list[0].good_stock,
              good_carton:list[0].good_carton,
              good_unit:list[0].good_unit,
              selected:JSON.parse(JSON.stringify(list[0].good_id)),
              selectArr:select_Arr
            }
            state.create_form.already_table.push(obj);
            console.log("菜单里",state.create_form.already_table)
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    //更改下拉
      function change_pro_sel(item,e) {
          console.log("旧数据",item);
          console.log(e);
        let origin=state.create_form.temp_data;
        console.log("获取origin",origin);
        let current_item=origin.find((v)=>v.good_id==e);
        console.log("匹配的数据",current_item);
        item.good_carton=current_item.good_carton;
        item.good_name=current_item.good_name;
        item.good_id=current_item.good_id;
        item.good_pur_price=current_item.good_pur_price;
        item.good_spec=current_item.good_spec;
        item.good_stock=current_item.good_stock;
        item.good_unit=current_item.good_unit;
        item.send_good_num=0;
    }
    //添加商品
      function addPro(){
        console.log("获取元",state.create_form.temp_data);
          let data=JSON.parse(JSON.stringify(state.create_form.temp_data[0]));
          data['selectArr']=state.create_form.select_data_arr;
          data['selected']=data.good_id;
          state.create_form.already_table.push(data);
      }
      function  del(idx) {
          state.create_form.already_table.splice(idx,1);
      }
    //  提交调拨的商品
      function onSubmit(){
        let items=[];
        let data=state.create_form.already_table;
        data.forEach((v)=>{
            let obj={
                id:v.good_id,
                count:v.send_good_num
            }
            items.push(obj)
        })
        let objdata={
          good_list:items,
          src_warehouse_id:state.create_form.out_ware_id,
            des_warehouse_id:state.create_form.in_ware_id,
            note:state.create_form.note,
            transport_fee:state.create_form.exdept_fee,
            other_fee:state.create_form.other_fee,
            deliver_way:state.create_form.deliver_way
        }
        let sss={data:JSON.stringify(objdata)}
          ctx.$http
              .post("/tanxiaji/allocate_create/",sss)
              .then((res) => {
                  if (res.errno == 0) {
                      state.set_dialogVisible=false;
                      getOrderlist();
                      ElNotification.success(res.errmsg);
                  } else {
                      ElNotification.error(res.errmsg);
                  }
              })
              .catch((err) => {
                  ElNotification.error(err);
              });
      }
    //  获取物流方式
      function get_carrier_ajax(){
          ctx.$http
              .get("/tanxiaji/allocate_get_carrier/")
              .then((res) => {
                  if (res.errno == 0) {
                      state.create_form.deliver_way_arr = res.data;
                  } else {
                      ElNotification.error(res.errmsg);
                  }
              })
              .catch((err) => {
                  ElNotification.error(err);
              });
      }
    // 查看详情
    function detailRow(item) {
      ctx.$http
        .get("/tanxiaji/allocate_inspect/", {
          allocation_id: item.id,
        })
        .then((res) => {
          if (res.errno == 0) {
            state.detail_dialog = true;
            state.detail_table = res.data.allocation_item;
            state.detail_obj = res.data;
            let code = res.data.status;
            let code_msg = "";
            switch (code) {
              case "创建":
                code_msg = 1;
                break;
              case "待配货":
              case "已拒绝":
                code_msg = 2;
                break;
              case "已发货":
                code_msg = 3;
                break;
              case "已完成":
                code_msg = 4;
                break;
            }
            state.step_num = code_msg;
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    // 确定入库
    function confirm_stock() {
      let data = state.trans_show_data;
      let allocation_list = [];
      data.forEach((v) => {
        let obj = {
          in_count: v.good_in_count,
          id: v.id,
        };
        allocation_list.push(obj);
      });
      let json_obj = {
        allocation_list: allocation_list,
        allocation_id: state.current_pro_id,
        other_fee: state.other_fee,
        note: state.trans_note,
        transport_fee: state.db_trans_fee,
      };
      ctx.$http
        .post("/tanxiaji/allocate_confirm/", {
          data: JSON.stringify(json_obj),
        })
        .then((res) => {
          if (res.errno == 0) {
            ElNotification.success(res.errmsg);
            state.trans_in_dialog = false;
            getOrderlist();
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    // 操作
    function optionBtn(item) {
      // 审核
      if (item.status == "待审核") {
        ElMessageBox.confirm(`是否通过审核？`, "提示", {
          confirmButtonText: "通过",
          cancelButtonText: "拒绝",
          distinguishCancelAndClose: true,
          type: "warning",
          center: true,
        })
          .then((action) => {
            approveAjax(item.id, 2);
          })
          .catch((action) => {
            if (action == "cancel") {
              approveAjax(item.id, 1);
            }
          });
      } else if (item.status == "待配货") {
        if (confirm("是否确认发货")) {
          send_good_ajax(item.id);
        }
      } else if (item.status == "已发货") {
        state.trans_in_dialog = true;
        get_alreay_send_good(item.id);
        state.current_pro_id = item.id;
      } else {
        ElNotification.error("此状态无操作");
      }
    }
    // ajax审核操作
    function approveAjax(id, type) {
      ctx.$http
        .post("/tanxiaji/allocate_check/", {
          allocation_id: id,
          status: type,
        })
        .then((res) => {
          if (res.errno == 0) {
            ElNotification.success(res.errmsg);
            getOrderlist();
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    // 获取已发货的接口
    function get_alreay_send_good(id) {
      ctx.$http
        .get("/tanxiaji/allocate_confirm_get_info/", {
          allocation_id: id,
        })
        .then((res) => {
          if (res.errno == 0) {
            let list = res.data;
            state.trans_show_data = list.allocation_item_lis;
            state.trans_note = list.note;
            state.other_fee = list.other_fee;
            state.db_trans_fee = list.transport_fee;
            state.good_total_in = list.good_total_in;
            state.good_total_out = list.good_total_out;
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    //获取仓库
    function get_ware_list() {
      ctx.$http
        .get("/tanxiaji/erp/depot/ajax/search/", {
          type: 1,
          need_agent: 1,
        })
        .then((res) => {
          if (res.errno == 0) {
            var list = res.data;
            state.wareData = list;
            state.create_form.in_ware_id=list[0].warehouse_id;
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    // 发货操作
    function send_good_ajax(id) {
      ctx.$http
        .post("/tanxiaji/allocate_deliver/", {
          allocation_id: id,
        })
        .then((res) => {
          if (res.errno == 0) {
            ElNotification.success(res.errmsg);
            getOrderlist();
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    //获取物流
    function get_log_list() {
      ctx.$http
        .get("/tanxiaji/allocate_get_carrier/", {})
        .then((res) => {
          if (res.errno == 0) {
            var list = res.data;
            state.logData = list;
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    //获取数据
    function getOrderlist() {
      ctx.$http
        .get("/tanxiaji/allocate_list/", {
          keyword: state.keyword,
          status: 0,
          page: state.page,
          begin_date: state.begin_date,
          end_date: state.end_date,
          verify_time: "",
          src_warehouse_id: state.trans_out_id,
          des_warehouse_id: state.trans_in_id,
        })
        .then((res) => {
          if (res.errno == 0) {
            var list = res.data.allocation_list;
            state.tableData = list;
          } else {
            ElNotification.error(res.errmsg);
          }
        })
        .catch((err) => {
          ElNotification.error(err);
        });
    }
    // 创建仓库
    return {
      dateFun,
      double,
      multipleTable,
      state,
      optionBtn,
      calcFun,
      confirm_stock,
      detailRow,
      new_trans,
      out_ware_change,
        change_pro_sel,
        addPro,
        del,
        create_calc,
        get_carrier_ajax,
        onSubmit
    };
  },
};
</script>
<style lang="scss" scoped>
.wrapper {
  height: 100%;
  .el-card {
    height: 100%;
    .cart-title::before {
      content: " ";
      width: 4px;
      height: 20px;
      background: #1890ff;
      background: #1890ff;
      display: inline-block;
      vertical-align: middle;
      margin-right: 5px;
    }
    .rowDiv {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      .row-left {
        display: flex;
        width: 70%;
        justify-content: space-between;
        .row-item {
          display: flex;
          align-items: center;
          white-space: nowrap;
        }
      }
      .row-right {
        width: 15%;
        display: flex;
        justify-content: flex-end;
      }
    }
    .el-table /deep/ th {
      background-color: #eaeaea;
      text-align: center;
    }
    .el-table /deep/ td {
      text-align: center;
    }
    .el-select {
      width: 100%;
    }
  }
}
</style>